package com.jmeurope.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jmeurope.dao.UserDao;
import com.jmeurope.model.User;
import com.jmeurope.service.UserService;
@Service
@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)  
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userDao;

	@Override
	public String addUser(User user) throws Exception {
		Integer userId = userDao.insert(user);
		return userId.toString();
	}

	@Override
	public void deleteUser(Integer id) throws Exception {
		userDao.delete(id);
	}

	@Override
	public User getUserByUserId(Integer id) throws Exception {
		return userDao.find(id);
	}

	@Override
	public List<User> getAllUsers() throws Exception {
		List<User> users = userDao.findAll();
		return users;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> getUsersByCondition(Map conditions) throws Exception {
		List<User> users = userDao.findByConditions(conditions);
		return users;
	}
}
